require "common/Define"
require "framework/BaseController"
require "FairyGUI"
require "Window3"
require "CoolComponent"

ParticlesMain = BaseController:New({mControllerName = "ParticlesMain"});

function ParticlesMain:Main()
	-- body
	ParticlesMain:Awake();
end

function ParticlesMain:Awake()
	-- body
	Application.targetFrameRate = 60;
	Stage.inst.onKeyDown:Add(self.OnKeyDown);

	-- load view
	fgui.register_extension("ui://Particles/CoolComponent", CoolComponent);

	-- attack pacakge, package in resource or assetbundle
	local packageName = "UI/Particles";
	UIPackage.AddPackage(packageName);

	local componentName = "Main";
	self.mainComponent = UIPackage.CreateObject("Particles", componentName).asCom;
	GRoot.inst:AddChild( self.mainComponent );

	self:OnViewCreated(self.mainComponent);
end

function ParticlesMain:InitView()
	local prefab = Resources.Load("Flame");
	local go = GameObject.Instantiate(prefab);
	self.mainComponent:GetChild("holder").asGraph:SetNativeObject( FairyGUI.GoWrapper.New(go) );

	self.mainComponent:GetChild("c0").draggable = true;
	self.mainComponent:GetChild("c1").draggable = true;
end

function ParticlesMain:OnKeyDown(context)
	if (context.inputEvent.keyCode == KeyCode.Escape) then
		Application.Quit();
	end
end